package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseServiceTypeVo;
import com.manage.modules.bo.TBaseServiceTypeQueryBo;
import com.manage.modules.bo.TBaseServiceTypeAddBo;
import com.manage.modules.bo.TBaseServiceTypeEditBo;
import com.manage.modules.service.ITBaseServiceTypeService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 维护类型Controller
 *
 * @author wx
 * @date 2021-08-17
 */
@Api(value = "维护类型控制器", tags = {"维护类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/serviceType")
public class TBaseServiceTypeController extends BaseController {

    private final ITBaseServiceTypeService iTBaseServiceTypeService;

    /**
     * 查询维护类型列表
     */
    @ApiOperation("查询维护类型列表")
    @PreAuthorize("@ss.hasPermi('modules:serviceType:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseServiceTypeVo> list(TBaseServiceTypeQueryBo bo) {
        startPage();
        List<TBaseServiceTypeVo> list = iTBaseServiceTypeService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出维护类型列表
     */
    @ApiOperation("导出维护类型列表")
    @PreAuthorize("@ss.hasPermi('modules:serviceType:export')")
    @Log(title = "维护类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseServiceTypeVo> export(TBaseServiceTypeQueryBo bo) {
        List<TBaseServiceTypeVo> list = iTBaseServiceTypeService.queryList(bo);
        ExcelUtil<TBaseServiceTypeVo> util = new ExcelUtil<TBaseServiceTypeVo>(TBaseServiceTypeVo.class);
        return util.exportExcel(list, "维护类型");
    }

    /**
     * 获取维护类型详细信息
     */
    @ApiOperation("获取维护类型详细信息")
    @PreAuthorize("@ss.hasPermi('modules:serviceType:query')")
    @GetMapping("/{serviceTypeId}")
    public AjaxResult<TBaseServiceTypeVo> getInfo(@PathVariable("serviceTypeId") Long serviceTypeId) {
        return AjaxResult.success(iTBaseServiceTypeService.queryById(serviceTypeId));
    }

    /**
     * 新增维护类型
     */
    @ApiOperation("新增维护类型")
    @PreAuthorize("@ss.hasPermi('modules:serviceType:add')")
    @Log(title = "维护类型", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseServiceTypeAddBo bo) {
        return toAjax(iTBaseServiceTypeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改维护类型
     */
    @ApiOperation("修改维护类型")
    @PreAuthorize("@ss.hasPermi('modules:serviceType:edit')")
    @Log(title = "维护类型", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseServiceTypeEditBo bo) {
        return toAjax(iTBaseServiceTypeService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除维护类型
     */
    @ApiOperation("删除维护类型")
    @PreAuthorize("@ss.hasPermi('modules:serviceType:remove')")
    @Log(title = "维护类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceTypeIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] serviceTypeIds) {
        return toAjax(iTBaseServiceTypeService.deleteWithValidByIds(Arrays.asList(serviceTypeIds), true) ? 1 : 0);
    }
}
